<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix"><span>图片轮播</span></div>
    <div>
      <el-collapse v-model="activeNames">
        <el-collapse-item title="组件" name="1">
          <draggable element="ul" v-model="data.imglist" :animation="500">
            <div class="item" v-for="(item, i) in data.imglist" :key="i">
              <i class="el-icon-error cancal" @click="delImg(i)"></i>
              <div class="img_box"><Upload :tempUrl="item.url" @input="getimg($event, item)"></Upload></div>
              <div class="item_select">
                <div @click="selectlink(item, i)"><Linkdiv :linkdata="item.linkdata"></Linkdiv></div>

                <span class="tip">建议图片宽度750px，高度跟随第一张图片的高度变化</span>
              </div>
            </div>
            <el-button @click="addimg">添加</el-button>
          </draggable>
        </el-collapse-item>
        <el-collapse-item title="组件样式" name="4">

          <el-form size="medium" label-width="100px">
                  <el-form-item label="背景类型">
                    <el-radio-group v-model="data.bg_type">
                      <el-radio :label="1">背景颜色</el-radio>
                      <el-radio :label="2">背景图片</el-radio>
                    </el-radio-group>
                  </el-form-item>
                  <el-form-item label="背景颜色" v-if="data.bg_type == 1"><ColorPicker :color="data" :name="'bg_color'"></ColorPicker></el-form-item>
                  <el-form-item label="背景图片" v-if="data.bg_type == 2">
                    <div class="img_box">
                        <Upload :tempUrl="data.bg_img" @input="getbgimg"></Upload>
                    </div>
                  </el-form-item>
                </el-form>

        </el-collapse-item>
        <el-collapse-item title="轮播点设置" name="2">
          <el-form size="medium" label-width="100px">
            <el-form-item label="样式">
              <el-radio-group v-model="data.type">
                <el-radio :label="1">圆角</el-radio>
                <el-radio :label="2">圆形</el-radio>
                <el-radio :label="3">数字</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="位置">
              <el-radio-group v-model="data.position">
                <el-radio :label="'flex-start'">居左</el-radio>
                <el-radio :disabled="data.type == 3" :label="'center'">居中</el-radio>
                <el-radio :label="'flex-end'">居右</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="选中颜色" v-if="data.type != 3"><ColorPicker :color="data" :name="'bg'"></ColorPicker></el-form-item>
          </el-form>
        </el-collapse-item>
        <el-collapse-item title="内容样式" name="3">
          <el-form size="medium" label-width="100px">
            <el-form-item label="上间距">
              <div class="slider_box">
                <el-slider class="slider_item" :max="50" v-model="data.p_t"></el-slider>
                <el-input-number v-model="data.p_t" :controls="false" :min="0" :max="50"></el-input-number>
              </div>
            </el-form-item>
            <el-form-item label="下间距">
              <div class="slider_box">
                <el-slider class="slider_item" :max="50" v-model="data.p_b"></el-slider>
                <el-input-number v-model="data.p_b" :controls="false" :min="0" :max="50"></el-input-number>
              </div>
            </el-form-item>
            <el-form-item label="左右间距">
              <div class="slider_box">
                <el-slider class="slider_item" :max="50" v-model="data.p_lr"></el-slider>
                <el-input-number v-model="data.p_lr" :controls="false" :min="0" :max="50"></el-input-number>
              </div>
            </el-form-item>
            <el-form-item label="上边角">
              <div class="slider_box">
                <el-slider class="slider_item" :max="50" v-model="data.r_t"></el-slider>
                <el-input-number v-model="data.r_t" :controls="false" :min="0" :max="50"></el-input-number>
              </div>
            </el-form-item>
            <el-form-item label="下边角">
              <div class="slider_box">
                <el-slider class="slider_item" :max="50" v-model="data.r_b"></el-slider>
                <el-input-number v-model="data.r_b" :controls="false" :min="0" :max="50"></el-input-number>
              </div>
            </el-form-item>
          </el-form>
        </el-collapse-item>
      </el-collapse>
    </div>
  </el-card>
</template>

<script>
import ColorPicker from '@/components/ColorPicker/index';

import Upload from '@/components/Upload/SingleImage2';
import Linkdiv from '@/components/Link/index';
import draggable from 'vuedraggable';
export default {
  props: {
    data: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      acivedata: {},
      activeNames: ['1', '2', '3','4']
    };
  },
  components: {
    draggable,
    Upload,
    ColorPicker,
    Linkdiv
  },

  mounted() {},
  methods: {
    /*选择器开始*/
    selectlink(item, i) {
      this.acivedata = item;
      this.activid = i;
      this.$parent.showlinkselcet(item);
    },
    getAData(item) {
      console.log(item)
      // this.data.imglist[this.activid].linkdata=item
      this.acivedata.linkdata = item;
    },

    getimg(data, item) {
      item.url = data;
    },
    getbgimg(data){
      this.data.bg_img=data
    },
    /*选择器结束*/

    //删除图片
    delImg(i) {
      this.data.imglist.splice(i, 1);
    },
    addimg() {
      this.data.imglist.push({
        url: '',
        linkdata:{
          link:'',
          name:'',
          id:'',
          type:''
        },
      });
    },
    change() {
      this.$emit('change', this.data);
    }
  }
};
</script>

<style scoped lang="scss">
::v-deep .el-collapse-item__wrap {
  overflow: visible;
}
// .bg-color {
//   border: 1px solid #e9edef;
//   box-sizing: border-box;
//   padding: 20px 20px 20px 0;
//   border-radius: 2px;
//   background: #f4f6f8;
// }
.item {
  position: relative;
  width: 100%;
  display: flex;
  cursor: pointer;
  background: #f4f6f8;
  border-radius: 2px;
  box-sizing: border-box;
  border: 1px solid #e9edef;
  margin-bottom: 10px;
  padding: 10px 10px;

  &:hover {
    .cancal {
      display: block;
    }
  }

  .cancal {
    font-size: 20px;
    position: absolute;
    right: -10px;
    top: -10px;
    cursor: pointer;
    display: none;
  }
}

.img_box {
  width: 60px;
  height: 60px;
}

.item_select {
  flex: 1;
  margin-left: 10px;
}

.tip {
  display: block;
  font-family: PingFang SC;
  font-style: normal;
  font-weight: normal;
  font-size: 12px;
  line-height: 18px;
  color: #939799;
  /* margin-top: 8px; */
}
</style>
